# Maintainer: Antoine Martin (ayakael) <dev@ayakael.net>
# Contributor: Antoine Martin (ayakael) <dev@ayakael.net>

#
# Variables for dotnet build version 3.1
# This APKBUILD is designed to be the same for version 5.0 and under
# except for the variables in this first section
#

pkgname=dotnet31-sdk
pkgver=3.1.418
_bldver=$pkgver-r0
pkgrel=0

# Following for dotnet build version 3.1 and up
_pkgver_macro=${pkgver%.*}
_pkgver_name=${_pkgver_macro//[.0]}
_bldver_ver=${_bldver%%-*}
pkgdesc="The .NET $_pkgver_macro SDK"
arch="x86_64"
url=https://www.microsoft.com/net/core
license="MIT"
makedepends="dotnet$_pkgver_name-build=$_bldver"

subpackages="
	dotnet$_pkgver_name:dotnet:noarch
	dotnet$_pkgver_name-templates:templates:noarch
	netstandard21-targeting-pack:netstandard_targeting_pack:noarch
	dotnet-zsh-completion:zshcomp:noarch
	dotnet-bash-completion:bashcomp:noarch
	dotnet-doc:doc:noarch
	"
options="!check" # No test suite
builddir="$srcdir"

# Function forces dependency on non-virtual host subpackages
# Overrides so that dependency to virtual host subpackage
# can be explicitely set from within subpackage functions
scan_symlink_targets() {
	return
}

build() {
	return
}

package() {
	depends="
		aspnetcore$_pkgver_name-runtime
		aspnetcore$_pkgver_name-targeting-pack
		dotnet$_pkgver_name-apphost-pack
		dotnet$_pkgver_name-targeting-pack
		dotnet$_pkgver_name-templates
		netstandard21-targeting-pack
		"
	provides="dotnet-sdk-$_pkgver_macro=$pkgver"

	install -dm 755 \
		"$pkgdir"/usr/share/dotnet \
		"$pkgdir"/usr/share/licenses \
		"$pkgdir"/usr/share/man/man

	cp -r /usr/share/dotnet/build/$_bldver_ver/sdk "$pkgdir"/usr/share/dotnet/.
	cp -r /usr/share/dotnet/build/$_bldver_ver/docs "$pkgdir"/usr/share/man/man
	ln -s dotnet-host "$pkgdir"/usr/share/licenses/dotnet$_pkgver_name-sdk
}

dotnet() {
	pkgdesc="The .NET $_pkgver_macro package"
	depends="dotnet$_pkgver_name-sdk"
	provides="dotnet-$_pkgver_macro=$pkgver"

	mkdir -p "$subpkgdir"
}

netstandard_targeting_pack() {
	pkgdesc="The .NET $_pkgver_macro Standard targeting pack"
	depends="dotnet-host"
	provides="netstandard-targeting-pack-2.1=$pkgver"

	install -dm 755 "$subpkgdir"/usr/share/dotnet/packs "$subpkgdir"/usr/share/licenses
	cp -r /usr/share/dotnet/build/$_bldver_ver/packs/NETStandard.Library.Ref "$subpkgdir"/usr/share/dotnet/packs/.
	ln -s dotnet-host "$subpkgdir"/usr/share/licenses/netstandard21-targeting-pack
}

templates() {
	pkgdesc="The .NET $_pkgver_macro templates"
	depends="dotnet-host"
	provides="dotnet-templates-$_pkgver_macro=$pkgver"

	install -dm 755 "$subpkgdir"/usr/share/dotnet "$subpkgdir"/usr/share/licenses
	cp -r /usr/share/dotnet/build/$_bldver_ver/templates "$subpkgdir"/usr/share/dotnet/.
	ln -s dotnet-host "$subpkgdir"/usr/share/licenses/dotnet$_pkgver_name-templates
}

zshcomp() {
	depends=""
	pkgdesc="zsh completion for .NET $_pkgver_macro"
	# netstandard21-targeting-pack will always be pulled by any dotnetx-sdk
	# thus pulling this with it for sdk
	install_if="netstandard21-targeting-pack zsh"

	install -dm 755	"$subpkgdir"/usr/share/zsh/site-functions
	install -m 755 /usr/share/dotnet/build/$_bldver_ver/comp/register-completions.zsh "$subpkgdir"/usr/share/zsh/site-functions/_dotnet
}

bashcomp() {
	depends=""
	pkgdesc="bash completion for .NET $_pkgver_macro"
	# netstandard21-targeting-pack will always be pulled by any dotnetx-sdk
	# thus pulling this with it for sdk
	install_if="netstandard21-targeting-pack bash-completion"

	install -dm 755	"$subpkgdir"/usr/share/bash-completion/completions
	install -m 755 /usr/share/dotnet/build/$_bldver_ver/comp/register-completions.bash "$subpkgdir"/usr/share/bash-completion/completions/_dotnet
}

doc() {
	default_doc
	pkgdesc="Docs for .NET $_pkgver_macro"
}
